package com.api.core.service.impl;

import com.api.common.enums.DataSourceType;
import com.api.core.domain.query.tracing.evaluation.EvaluationScroeQuery;
import com.api.core.domain.query.tracing.evaluation.EvaluationSeriesQuery;
import com.api.core.domain.vo.tracing.evaluation.EvalScoreVo;
import com.api.core.domain.vo.tree.TreeVo;
import com.api.core.mapper.EvaluationMapper;
import com.api.core.service.IEvaluationService;
import com.api.framework.datasource.DynamicDataSourceContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluationServiceImpl implements IEvaluationService {
    @Autowired
    EvaluationMapper evaluationMapper;
    @Override
    public List<Double> generates(TreeVo vo) {
        String tableName = vo.getEvaluationTabName();
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        List<Double> dataList = evaluationMapper.generates(tableName, vo);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return dataList;
    }

    @Override
    public List<EvaluationScroeQuery> scroe(EvalScoreVo vo) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        vo.initTableName();
        List<EvaluationScroeQuery> dataList = evaluationMapper.scroe(vo);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return dataList;
    }

    @Override
    public EvaluationSeriesQuery series(EvalScoreVo vo) {
        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
        vo.initTableName();
        EvaluationSeriesQuery data = evaluationMapper.series(vo);
        DynamicDataSourceContextHolder.clearDataSourceType();
        return data;
    }
}
